var originalAbility;

var typeArray = [ Type.BLAZE, Type.ELECTRO ];

var typedAbilities = {
	"Blaze": {
		name: "Burning Fist",
		desc: "Throw 1 to 3 burning fist(s) at the target, for 20 base damage each!",
		target: Targetable.OPPONENT_ANY,
		callback: function(ability, unit, user, target) {
			var times = randomValue(1, 3);
			
			while(times-- > 0) {
				var dmg = target.dealDamage(20, Type.BLAZE);
				unit.session.narrate(unit.name + " punches at " + target.name + " for a blazing " + dmg + " damage!");
			}
			return true;
		}
	},
	"Electro": {
		name: "Electro-Blast",
		desc: "The target is electrocuted twice, causing a random base damage between 8 and 20!",
		target: Targetable.OPPONENT_ANY,
		callback: function(ability, unit, user, target) {
			for(var i = 0; i < 2; i++) {
				var dmg = target.dealDamage( randomValue(8, 20) , Type.ELECTRO);
				unit.session.narrate(unit.name + " delivers a shocking blow to " + target.name + ", dealing " + dmg + " damage!");
			}
			return true;
		}
	}
};

function setupCardData() {
	card.name = "Elemental Typegolem";
	card.desc = "A special golem that, when placed, gains a random elemental type with a matching ability!";
	card.refId = "se.kayarr.default.elemental_typegolem";
	card.maxHealth = 80;
	
	originalAbility = card.addAbility(
		"Typed Ability",
		"When placed, the card will be assigned a random elemental type (Blaze, Aqua, Electro or Vegetation) and a related ability.",
		Targetable.NONE,
		null
	);
}

function onPlaced(unit) {
	unit.removeAbility(originalAbility);
	
	unit.type = typeArray[ randomValue(0, typeArray.length) ];
	var a = typedAbilities[ unit.type ];
	unit.addAbility(a.name, a.desc, a.target, a.callback);
	
	unit.session.narrate("As " + unit.name + " is placed, it becomes " + unit.type + "-type, gaining the ability \"" + a.name + "\"!");
}

function randomValue(min, max) {
	return Math.floor( Math.random()*(max-min) + min );
}